import { ref } from 'vue';
import SourceManagement from '../pages/SourceManagement.vue';
import HerbManagement from '../pages/HerbManagement.vue';
import EfficacyManagement from '../pages/EfficacyManagement.vue';

const useDatabase = () => {
  const currentTable = ref(SourceManagement);
  const currentData = ref([]);

  const selectTable = (table) => {
    console.log('Selecting table:', table); // 添加日志以调试
    switch (table) {
      case 'source':
        currentTable.value = SourceManagement;
        currentData.value = [
          { name: '药材1', source: '基源1', origin: '产地1', collectionTime: '2023-01-01' },
          { name: '药材2', source: '基源2', origin: '产地2', collectionTime: '2023-02-01' }
        ];
        break;
      case 'herb':
        currentTable.value = HerbManagement;
        currentData.value = [
          { name: '药材A', description: '描述A', price: '100元' },
          { name: '药材B', description: '描述B', price: '200元' }
        ];
        break;
      case 'efficacy':
        currentTable.value = EfficacyManagement;
        currentData.value = [
          { herb: '药材X', efficacy: '功效X', usage: '用法X' },
          { herb: '药材Y', efficacy: '功效Y', usage: '用法Y' }
        ];
        break;
      default:
        currentTable.value = SourceManagement;
        currentData.value = [];
    }
  };

  return { currentTable, currentData, selectTable };
};

export { useDatabase };